package com.itheima.controller;


import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionAdviceHandler {

    @ExceptionHandler(DataIntegrityViolationException.class)
    public Result dive(DataIntegrityViolationException e){
        System.out.println(e.getMessage());
        String msg = "反正你的问题";
        if (e.getMessage().contains("Data too long")){
            msg = "你输入的字母太长";
        }
        return new Result(Code.DAO_ERR,null,msg);
    }
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {

        System.out.println(e.getMessage());
        return new Result(Code.ERR_ERR, null, "8BQ了~网络出问题了");
    }
}
